﻿namespace OrderStateMachineWebApi.Models
{

    public class Order
    {
        public Guid Id { get; set; }
        public string OrderNumber { get; set; }
        public OrderStatus Status { get; set; }
        public decimal Amount { get; set; }
        public DateTime CreatedAt { get; set; }
        public DateTime? UpdatedAt { get; set; }
        public string? Notes { get; set; }

        public Order()
        {
            Id = Guid.NewGuid();
            OrderNumber = GenerateOrderNumber();
            Status = OrderStatus.PendingPayment;
            CreatedAt = DateTime.UtcNow;
        }

        private string GenerateOrderNumber()
        {
            return $"ORD-{DateTime.UtcNow:yyyyMMddHHmmss}-{Guid.NewGuid().ToString().Substring(0, 6).ToUpper()}";
        }
    }

    public enum OrderStatus
    {
        PendingPayment,   // 待支付
        Paid,             // 已支付
        Processing,       // 处理中
        Shipped,          // 已发货
        Completed,        // 已完成
        Cancelled,        // 已取消
        Refunding,        // 退款中
        Refunded          // 已退款
    }
}
